<template>
	<view class="contianer">
		<view class="con_title">修改手机号</view>
		<view class="con_mian">
			<view class="mian_item">
				<view class="item_left">
					<image class="icon" src="../../static/img/phone.png" mode=""></image>
					<text style="display: block;  margin: 0 12px 0 6px;">+86</text>
					<input type="number" maxlength="11" placeholder="请输入手机号" v-model="phone" />
				</view>
				<view class="">

				</view>
			</view>
			<view class="mian_item">
				<view class="item_left">
					<image class="icon" style="margin-right: 10px;" src="../../static/img/anquan.png" mode=""></image>
					<input type="number" placeholder="请输入验证码" maxlength="6" v-model="send" />
				</view>
				<view>
					<u-toast ref="uToast"></u-toast>
					<u-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-code>
					<u-button class="wrap" @tap="getCode">{{tips}}</u-button>
				</view>
			</view>
		</view>

		<view class="btn" @click="changemobile()">
			确认换绑
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: "",
				send: "",
				tips: '',
				// refCode: null,
				seconds: 10,
			}
		},
		onLoad() {

		},
		methods: {
			changemobile(){
				this.postchangemobile()
			},
			async postchangemobile(){
				const res = this.$api('/api/user/changemobile','post',{
					mobile:this.phone,
					captcha:this.send
				}).then((res)=>{
					console.log(res);
					uni.$u.toast(res.data.msg)
				}).catch((err)=>{
					console.log(err);
					uni.$u.toast(err.data.msg)
				})
			},
			async getsend() {
				const res = this.$api("/api/sms/send", 'post', {
					mobile: this.phone
				}).then((res) => {
					console.log(res);
					console.log(res.data);
					uni.$u.toast(res.data.msg);
				}).catch((err) => {
					console.log(err);
					uni.$u.toast(err.data.msg);
				})
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					if (this.phone) {
						this.getsend()
					} else {
						uni.$u.toast('请先输入手机号');
					}
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			end() {
				// uni.$u.toast('倒计时结束');
			},
			start() {
				// uni.$u.toast('倒计时开始');
			}
		}
	}
</script>

<style lang="scss" scoped>
	view {
		box-sizing: border-box;
		font-family: PingFang SC, PingFang SC;
	}


	.wrap {
		background: #FB774B;
		border-radius: 26px;
		border: none;
		text-align: center;
		color: #fff;
		font-size: 12px;
		padding: 10px 5px;
		height: 26px;
	}

	.contianer {
		background-color: #FFF;
		padding: 20px 15px;

		.con_title {
			font-weight: bold;
			color: #333333;
			font-size: 20px;
			margin-bottom: 50px;
		}

		.con_mian {
			.mian_item {
				height: 55px;
				width: 100%;
				margin-bottom: 20px;
				display: flex;
				justify-content: space-between;
				border-bottom: 1px solid #EEEEEE;
				align-items: center;

				.item_left {
					flex: 1;
					// height: 100%;
					display: flex;
					align-items: center;
					font-size: 16px;
					color: #999999;

					.icon {
						width: 18px;
						height: 18px;
						// background-color: #FB774B;
					}
				}

				.item_btn {
					height: 26px;
					background: #FB774B;
					border-radius: 26px 26px 26px 26px;
					padding: 5px 9px;

					color: #FFFFFF;
					font-weight: bold;
					font-size: 11px;
				}
			}
		}

		.btn {
			margin-top: 100px;
			font-weight: bold;
			color: #FFFFFF;
			height: 40px;
			background: #FB774B;
			border-radius: 40px 40px 40px 40px;
			font-size: 16px;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>